﻿

CREATE PROCEDURE [dbo].[fares_FiltreazaDocumente] 
	-- Add the parameters for the stored procedure here
	@filtru varchar(500),
	@an varchar(4)
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	DECLARE @sel varchar(2000)
	SET @sel = 'SELECT * FROM [Documente'+@an+'] where IDDocument in 
		(select [Documente'+@an+'].IDDocument FROM [Documente'+@an+']  JOIN [DocumenteDetaliu'+@an+']  ON [Documente'+@an+'].IDDocument = [DocumenteDetaliu'+@an+'].IDDocument WHERE ' +@filtru  + ')'
	EXEC(@sel)
END